<?php
	class planovanie extends BaseController{
		const ROUND_TABLE = "roundTable";
        public $security_level = SECURITY_LEVEL_ADMIN;

		public function getData($in_params){
			return;
		}

        public function action_save($in_params = array()){
            $data_path = "./resources/tempTables.json";
            if (array_key_exists("data", $in_params)){
                $data = $in_params["data"];
                $handle = fopen($data_path, 'w');
                fwrite($handle, json_encode($data));
                fclose($handle);
                return $data;
            }
            return false;
        }

        public function action_submit($in_params = array()){
            $data_path = "./resources/tables.json";
            if (array_key_exists("data", $in_params)){
                $data = $in_params["data"];
                $handle = fopen($data_path, 'w');
                fwrite($handle, json_encode($data));
                fclose($handle);
                $tables = array();
                foreach($data as $item){
                    switch($item["type"]){
                        case static::ROUND_TABLE:
                            $id = $item["state"]["id"];
                            $count = $item["state"]["seatCount"];
                            $seats = array();
                            for($i = 0; $i < $count; $i++){
                                $seats[] = $id . "_s" . $i;
                            }
                            $tables[] = array("id" => $id, "seats" => $seats);
                            break;
                    }
                }
                $reservation = new InteractiveReservation();
                $reservation->Save($tables);
                return $data;
            }
            return false;
        }
	}
?>